package com.example.usermanagement.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "通用响应结果")
public class CommonResponse<T> {
    @Schema(description = "状态码：200表示成功，其他表示失败")
    private int code;

    @Schema(description = "响应消息")
    private String message;

    @Schema(description = "响应数据")
    private T data;

    public static <T> CommonResponse<T> success() {
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(200);
        response.setMessage("操作成功");
        return response;
    }

    public static <T> CommonResponse<T> success(T data) {
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(200);
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    public static <T> CommonResponse<T> fail(int code, String message) {
        CommonResponse<T> response = new CommonResponse<>();
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}
